const Router = require("@koa/router");
const router = new Router({ prefix: "/carts" });
const { auth } = require("../middleware/authMiddleware");
const { validator } = require("../middleware/cartMiddleware");
const {
  add,
  findAll,
  update,
  remove,
  selectAll,
  unselectAll,
} = require("../controller/cartController");
// 1. 添加购物车
router.post("/", auth, validator({ goods_id: "number" }), add);
// 2. 获取购物车列表
router.get("/", auth, findAll);
// 3. 更新购物车
router.patch(
  "/:id",
  auth,
  validator({
    number: { type: "number", required: false },
    selected: { type: "bool", required: false },
  }),
  update
);
// 4. 删除购物车
router.delete("/", auth, validator({ ids: "array" }), remove);
// 5. 全选
router.post("/selectAll", auth, selectAll);
// 6. 全不选
router.post("/unselectAll", auth, unselectAll);
// 7. 购物车数量
module.exports = router;
